package com.itheima.admin.listener;

import com.itheima.admin.service.WemediaNewsAutoScanService;
import com.itheima.common.constants.BusinessConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @version 1.0
 * @description 说明
 * @package com.itheima.admin.listener
 */
@Component
@Slf4j
public class WemediaNewsAutoScanListener {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;

    /**
     * 文章自动审核
     * @param consumerRecord
     */
    @KafkaListener(topics = BusinessConstants.MqConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void autoScanWemediaNews(ConsumerRecord<String,String> consumerRecord){
        String topic = consumerRecord.topic();
        int partition = consumerRecord.partition();
        String newsId = consumerRecord.value();
        String uuid = UUID.randomUUID().toString();
        log.info("自动审核开始：uuid={},id={},t={},p={}",uuid,newsId,topic,partition);
        //TODO 审核业务
        wemediaNewsAutoScanService.autoScanWemediaNewsById(newsId,uuid);
        log.info("自动审核结束：uuid={},id={},t={},p={}",uuid,newsId,topic,partition);

    }
}
